package leetcode.median;

/**
 * ClassName: $24_SearchMatrix
 * Description:
 * date: 2022-02-19 9:22
 *
 * @author liyifan
 */
public class $240_SearchMatrix {
    public boolean searchMatrix(int[][] matrix, int target) {
        int row = matrix.length;
        int col = matrix[0].length;
        if (row == 0 || col == 0)
            return false;

        int i = 0;
        int j = col - 1;
        while (i < row && j >= 0) {
            if (matrix[i][j] == target) {
                // 找到了
                return true;
            } else if (matrix[i][j] < target) {
                // 向下搜
                i++;
            } else {
                // 向左搜索
                j--;
            }
        }
        return false;
    }
}
